home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / boot / czesc_2 / toolmanager / source / prefs / aslreqs.c < prev    next >
C/C++ Source or Header  |  1993-05-15  |  6KB  |  180 lines

  1. /*
  2.  * aslreqs.c  V2.1
  3.  *
  4.  * file & font requester handling
  5.  *
  6.  * (c) 1990-1993 Stefan Becker
  7.  */
  8.  
  9. #include "ToolManagerConf.h"
  10.  
  11. /* Handle window IDCMP's */
  12. __stkargs static struct IntuiMessage *RequesterHook(ULONG mask,
  13.                                                     struct IntuiMessage *msg,
  14.                                                     void *dummy)
  15. {
  16.  if (mask==FRF_INTUIFUNC) { /* FOF_INTUIFUNC == FRF_INTUIFUNC */
  17.   /* Only refresh events are executed */
  18.   if (msg->Class==IDCMP_REFRESHWINDOW) {
  19.    struct Window *w=msg->IDCMPWindow;
  20.  
  21.    /* Execute GadTools refresh */
  22.    GT_BeginRefresh(w);
  23.    GT_EndRefresh(w,TRUE);
  24.   }
  25.  
  26.   /* Return pointer to original IntuiMessage */
  27.   return(msg);
  28.  }
  29.  return(0);
  30. }
  31.  
  32. /* Open a file requester */
  33. char *OpenFileRequester(struct Requester *req)
  34. {
  35.  struct Window *w;
  36.  ULONG oldidcmp;
  37.  char *oldfile,*filepart,*pattern;
  38.  char *dirname=NULL,*newfile=NULL;
  39.  ULONG len;
  40.  
  41.  w=FileReqParms.frp_Window;
  42.  oldidcmp=w->IDCMPFlags;
  43.  DisableWindow(w,req);
  44.  
  45.  /* Split old file name */
  46.  oldfile=FileReqParms.frp_OldFile;
  47.  filepart=FilePart(oldfile);
  48.  
  49.  /* Got a directory? Can we allocate memory for name? */
  50.  len=filepart-oldfile+1;
  51.  if (dirname=malloc(len)) {
  52.   struct FileRequester *filereq;
  53.  
  54.   if (len>1) strncpy(dirname,oldfile,len-1);
  55.   dirname[len-1]='\0';
  56.  
  57.   /* Select Pattern */
  58.   if (FileReqParms.frp_Flags2 & FRF_REJECTICONS)
  59.    pattern="~(#?.info)";
  60.   else
  61.    pattern="#?";
  62.  
  63.   /* Allocate File Requester */
  64.   if (filereq=AllocAslRequestTags(ASL_FileRequest,
  65.                                   ASLFR_Window,          w,
  66.                                   ASLFR_InitialLeftEdge, w->LeftEdge,
  67.                                   ASLFR_InitialTopEdge,  w->TopEdge+WindowTop,
  68.                                   ASLFR_TitleText,     FileReqParms.frp_Title,
  69.                                   ASLFR_PositiveText,  FileReqParms.frp_OKText,
  70.                                   ASLFR_NegativeText,
  71.                                     AppStrings[MSG_FILEREQ_CANCEL_GAD],
  72.                                   ASLFR_Flags1,       FileReqParms.frp_Flags1 |
  73.                                                       FRF_INTUIFUNC,
  74.                                   ASLFR_Flags2,       FileReqParms.frp_Flags2,
  75.                                   ASLFR_HookFunc,        RequesterHook,
  76.                                   ASLFR_InitialDrawer,   dirname,
  77.                                   ASLFR_InitialFile,     filepart,
  78.                                   ASLFR_InitialPattern,  pattern,
  79.                                   TAG_DONE)) {
  80.    /* Show requester */
  81.    if (AslRequest(filereq,NULL)) {
  82.     /* Build file name */
  83.     len=strlen(filereq->fr_File)+1;
  84.  
  85.     /* File name valid or drawers only? */
  86.     if ((len>1) || (FileReqParms.frp_Flags2 & FRF_DRAWERSONLY)) {
  87.      /* Add drawer string length */
  88.      if (filereq->fr_Drawer) len+=strlen(filereq->fr_Drawer)+1;
  89.  
  90.      /* Allocate memory for string */
  91.      if (newfile=malloc(len)) {
  92.       *newfile='\0';
  93.       if (filereq->fr_Drawer) strcpy(newfile,filereq->fr_Drawer);
  94.       if (!(FileReqParms.frp_Flags2 & FRF_DRAWERSONLY))
  95.        AddPart(newfile,filereq->fr_File,len);
  96.      }
  97.     }
  98.    }
  99.    FreeAslRequest(filereq);
  100.   }
  101.   free(dirname);
  102.  }
  103.  
  104.  /* Enable old window */
  105.  EnableWindow(w,req,oldidcmp);
  106.  
  107.  /* return new file name */
  108.  return(newfile);
  109. }
  110.  
  111. static struct TextAttr dummyta;
  112.  
  113. /* Open a file requester */
  114. struct TextAttr *OpenFontRequester(struct Window *w, struct Requester *req,
  115.                                    struct TextAttr *oldfont)
  116. {
  117.  struct FontRequester *fontreq;
  118.  struct TextAttr *curfont,*newfont=NULL;
  119.  ULONG oldidcmp;
  120.  
  121.  /* Switch off edit window IDCMP */
  122.  oldidcmp=w->IDCMPFlags;
  123.  DisableWindow(w,req);
  124.  
  125.  /* Set font */
  126.  if (oldfont)
  127.   curfont=oldfont;
  128.  else
  129.   curfont=&ScreenTextAttr;
  130.  
  131.  /* Allocate font requester */
  132.  if (fontreq=AllocAslRequestTags(ASL_FontRequest,
  133.                                  ASLFO_Window,          w,
  134.                                  ASLFO_InitialLeftEdge, w->LeftEdge,
  135.                                  ASLFO_InitialTopEdge,  w->TopEdge+WindowTop,
  136.                                  ASLFO_TitleText,
  137.                                    AppStrings[MSG_FONTREQ_TITLE],
  138.                                  ASLFO_PositiveText,
  139.                                    AppStrings[MSG_FILEREQ_OK_GAD],
  140.                                  ASLFO_NegativeText,
  141.                                    AppStrings[MSG_FILEREQ_CANCEL_GAD],
  142.                                  ASLFO_Flags,           FOF_DOSTYLE|
  143.                                                         FOF_INTUIFUNC,
  144.                                  ASLFO_HookFunc,        RequesterHook,
  145.                                  ASLFO_InitialName,     curfont->ta_Name,
  146.                                  ASLFO_InitialSize,     curfont->ta_YSize,
  147.                                  ASLFO_InitialStyle,    curfont->ta_Style,
  148.                                  ASLFO_InitialFlags,    curfont->ta_Flags,
  149.                                  TAG_DONE)) {
  150.  
  151.   DEBUG_PRINTF("FontRequester 0x%08lx\n",fontreq);
  152.  
  153.   /* Show requester */
  154.   if (AslRequest(fontreq,NULL)) {
  155.    /* User selected new font */
  156.    char *f=fontreq->fo_Attr.ta_Name;
  157.    char *s=NULL;
  158.  
  159.    DEBUG_PRINTF("Font name '%s'",f);
  160.    DEBUG_PRINTF(" (0x%08lx)\n",f);
  161.  
  162.    /* Copy font name (Pointer valid? Valid font name (that is "*.font")? */
  163.    if (!f || (strlen(f)<6) || (s=strdup(f))) {
  164.     /* All OK. */
  165.     dummyta=fontreq->fo_Attr;
  166.     dummyta.ta_Name=s;        /* s==NULL if NO font selected! */
  167.     newfont=&dummyta;
  168.    }
  169.   }
  170.  
  171.   FreeAslRequest(fontreq);
  172.  }
  173.  
  174.  /* Enable old window */
  175.  EnableWindow(w,req,oldidcmp);
  176.  
  177.  /* return new file name */
  178.  return(newfont);
  179. }
  180.